﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FortuneCat.WebUI.Infrastructure.Abstract;
using FortuneCat.Domain.Abstract;
using System.Web.Security;

namespace FortuneCat.WebUI.Infrastructure.Concrete {
    public class EFAuthProvider : IAuthProvider {
        private IUserRepository _userRepository;

        public EFAuthProvider(IUserRepository userRepository) {
            _userRepository = userRepository;
        }

        public bool Authenticate(string username, string password) {
            bool result = _userRepository.Items.Any(x => x.UserName.ToLower() == username.ToLower() && x.Password.ToLower() == password.ToLower());
            if (result) {
                FormsAuthentication.SetAuthCookie(username, false);
            }
            return result;
        }

        public void LogOff() {
            FormsAuthentication.SignOut();
        }
    }
}